// pages/Home/home.js
import { in_theaters ,coming_soon, selectPreview} from "../../utils/home/index"
var Tx = require('../../utils/qqmap-wx-jssdk.js');
var qqmapsdk = new Tx({
    key: 'TKOBZ-S6UCP-B4YDB-LQZJF-5JNB2-WGBUX' // 必填
});  
Page({

    data: {
        city:"",
        indicatorDots:true,
        autoplay:true,
        interval:3000,
        duration:500,
        hotlist:[],
        comingsList:[],
        NoticeList:[],
    },
    // 获取位置信息
    getLocation(){
        var _this = this
        wx.getLocation({
            success(res){
                 console.log(res);
                 qqmapsdk.reverseGeocoder({
                    location:`${res.latitude},${res.longitude}`,
                    success(val){
                        console.log(val);
                        _this.setData({
                            city:val.result.address_component.city
                        })
                        wx.setStorageSync("city",val.result.address_component.city)
                    }
                 })    
            }
        })
    },
    //获取 热映影片列表
    ishot(){    
        in_theaters().then(res=>{
            // console.log(res);
            this.setData({
                hotlist:res.data.data.list
            })
         
            
        })
    },
    // 获取即将上映列表
    comimgs(){
        coming_soon().then(res=>{
            console.log(res);
            this.setData({
                comingsList:res.data.data.list
            })
            
        })
    },
    // 获取精选预告
    Notice(){
        selectPreview().then(res=>{
            console.log(res);
            this.setData({
                NoticeList:res.data.data
            })
            console.log(this.data.NoticeList);
        })
        
    },
    onLoad(){
        this.ishot()
        this.comimgs()
        this.Notice()
    },
    onShow(){
        this.getLocation()
    }
})